﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage<SuperStarProject.Models.PhieuMuaHangModel>" %>



<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">
	Chỉnh sửa phiếu mua hàng
</asp:Content>

<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
    <script type="text/javascript" language="javascript">
        function GetMaDaiLy() {
            var maDaiLy = document.getElementsByName("DaiLyListBox")[0].value;
            document.getElementsByName("MaDaiLy")[0].value = maDaiLy;
        }
        function TinhTien() {
            var diemthuong = parseInt(document.getElementsByName("DiemThuong")[0].value);
            var soluong = parseInt(document.getElementsByName("SoLuongComBo")[0].value);
            var dongia = parseInt(document.getElementsByName("GiaTriTien")[0].value);
            var tong = soluong * dongia;
            document.getElementsByName("TongTien")[0].value = tong;
            document.getElementsByName("SoLuongMua")[0].value = soluong;
            document.getElementsByName("TongDiemThuong")[0].value = soluong * diemthuong;
        }
        function UpdateSoLuongToiDa() {
            var soluong = parseInt(document.getElementsByName("SoLuong")[0].value);
            var soluongcombo = parseInt(document.getElementById("SoLuongMaxCombo").value);
            if (soluongcombo != 0) {
                var tong = soluong + soluongcombo;
                for (var i = soluongcombo + 1; i <= tong; i++) {
                    var oOption = document.createElement("OPTION");
                    oOption.setAttribute("value", i);
                    oOption.innerHTML = i.toString();
                    document.getElementById("SoLuongComBo").appendChild(oOption);
                }
                document.getElementById("SoLuongMaxCombo").value = 0;
            }
        }
    </script>
    <h2>Chỉnh sửa phiếu mua hàng</h2>
                          	<div class="contact_form"> 
                <div class="form_subtitle">Sản phẩm</div> 
                <% Html.RenderAction("ViewDetailsLocal", "Product", new { productId = Model.MaSP }); %>
                    <div class="uc_form_row"> 
                    <label class="uc_contact"><strong>Số lượng mua cũ:</strong></label> 
                    <%=Html.TextBox("SoLuongMaxCombo", Model.SoLuongMua, new { @readonly = "readonly" })%>
                    </div> 
                    <div class="uc_form_row"> 
                    <label class="uc_contact"><strong>Đ.thưởng cũ:</strong></label> 
                    <%=Html.TextBox("DiemThuong", Model.TongDiemThuong.ToString(), new { @readonly = "readonly" })%>
                    </div> 
                    
            </div>
<div class="clear"></div>
                                      	<div class="contact_form"> 
                <div class="form_subtitle">Sản phẩm</div> 
                   <% Html.RenderAction("ShowAllDaiLy", "DaiLy");%><br />
                   <label class="uc_contact"><strong>Số lượng:</strong></label> 
                   <select class="uc_contact_input" name="SoLuongComBo" id="SoLuongComBo" onchange="TinhTien();" onfocus="UpdateSoLuongToiDa();">
                    <% for(int i =1; i <= Model.SoLuongMua ;i++)
                        {%>
                            <option value=<%=i%>><%=i%></option>
                    <% }%>
            </select>
            
    <% using (Html.BeginForm()) {%>
        <%= Html.ValidationSummary(true) %>

                </div>
            <div class="clear"></div>
                <%= Html.HiddenFor(model => model.MaPhieuMuaHang) %>

                <%= Html.HiddenFor(model => model.MaKH) %>
          
                <%= Html.HiddenFor(model => model.MaSP) %>

                <%= Html.HiddenFor(model => model.MaDaiLy) %>
                <div class="contact_form"> 
                <div class="form_subtitle">Thông tin mới</div> 
                                    <div class="form_row"> 
                    <label class="contact"><strong>Tổng đ.thưởng mới:</strong></label> 
                    <%= Html.TextBoxFor(model => model.TongDiemThuong, new { @readonly = "readonly"})%>
                    </div> 
                    <div class="form_row"> 
                    <label class="contact"><strong>Giá trị thanh toán mới:</strong></label> 
                     <%= Html.TextBoxFor(model => model.TongTien, new { @readonly = "readonly"})%>
                    </div> 
                
                <%= Html.HiddenFor(model => model.TongDiemThuongDaSuDung) %>            

                <%= Html.HiddenFor(model => model.NgayMua, String.Format("{0:g}", Model.NgayMua))%>

                <%= Html.HiddenFor(model => model.SoLuongMua)%>

                <%= Html.HiddenFor(model => model.TinhTrangGiao)%>

                <%= Html.HiddenFor(model => model.NgayNhan, String.Format("{0:g}", Model.NgayNhan))%>
<div class="form_row">
                <input type="submit" class="register" value="Chỉnh sửa" /></div>
                hoặc<br />
                <%= Html.ActionLink("Hủy phiếu mua hàng", "Delete", new { maphieumuahang = Model.MaPhieuMuaHang })%>
                </div>
    <% } %>
</asp:Content>

